import type {
  CodeType,
  Patient,
  PatientList,
  User,
  UserInfo
} from '@/types/user'
import { request } from '@/utils/request'

// 用户登录
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', {
    mobile,
    password
  })
}

// 获取验证码
export const getCode = (mobile: string, type: CodeType) => {
  return request('code', 'GET', {
    mobile,
    type
  })
}

// 短信登录
export const loginByMobile = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

// 获取个人信息
export const getUserInfo = () => {
  return request<UserInfo>('/patient/myUser')
}

// 获取患者信息列表
export const getPatientList = () => {
  return request<PatientList>('/patient/mylist')
}

// 添加患者
export const addPatient = (patient: Patient) => {
  return request<Patient>('/patient/add', 'POST', patient)
}

// 编辑患者信息
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

// 删除患者信息
export const delPatient = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}

// 查询患者详细
export const getPatientDetail = (id: string) => {
  return request<Patient>(`/patient/info/${id}`)
}

// qq登录
export const loginByQQ = (openId: string) => {
  return request<User>('/login/thirdparty', 'POST', {
    openId,
    source: 'qq'
  })
}

// 绑定手机号
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => {
  return request<User>('/login/binding', 'POST', data)
}
